<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/11
 * Time: 20:12
 */
require S_ROOT . 'source/newjpush/autoload.php';
require_once(S_ROOT."source/newjpush/src/JPush/Client.php");

//用户签到提醒推送
$app_key = '0ca71dd1e25c381e137e3e9e';
$master_secret = '4ec9d804659b04b8173f1ed0';
$client = new Client($app_key, $master_secret);

$sql = "select uid,pt,remind_time from tttj.remind_goods WHERE appid = 95";
$time = date('H',time());
$list = getarrrecord($sql);
foreach ($list as $k => $v) {
    $content = '爱打折商品预约提醒';
    if($time == '9' && $v['remind_time'] == '10'){
        if ($v['pt'] == 1) {
            $device = 'android';
            $pttype['pt'] = '1';
        } else {
            $device = 'ios';
            $pttype['pt'] = '2';
        }
        try {
            $result = $client->push();
            $result->setPlatform($device);
            $result->addAlias($v['uid']);
            $result->setNotificationAlert($content);
            if ($pttype['pt'] == 1) {
                $result->androidNotification($content, array('title' => '爱打折', 'builder_id' => 1, 'extras' => array()));
            } else {
                $result->iosNotification($content, array('sound' => 'sound', 'badge' => '+1', 'content-available' => null, 'mutable-content' => null, 'category' => null, 'extras' => array()));
            }
            $result->setOptions(100000, 86400, null, false);
            $result->send();
        } catch (Exception $e) {
            echojson('操作成功', 1, $datas);
        }
    }

    if($time == '11' && $v['remind_time'] == '12'){
        if ($v['pt'] == 1) {
            $device = 'android';
            $pttype['pt'] = '1';
        } else {
            $device = 'ios';
            $pttype['pt'] = '2';
        }
        try {
            $result = $client->push();
            $result->setPlatform($device);
            $result->addAlias($v['uid']);
            $result->setNotificationAlert($content);
            if ($pttype['pt'] == 1) {
                $result->androidNotification($content, array('title' => '爱打折', 'builder_id' => 1, 'extras' => array()));
            } else {
                $result->iosNotification($content, array('sound' => 'sound', 'badge' => '+1', 'content-available' => null, 'mutable-content' => null, 'category' => null, 'extras' => array()));
            }
            $result->setOptions(100000, 86400, null, false);
            $result->send();
        } catch (Exception $e) {
            echojson('操作成功', 1, $datas);
        }
    }

    if($time == '12' && $v['remind_time'] == '13'){
        if ($v['pt'] == 1) {
            $device = 'android';
            $pttype['pt'] = '1';
        } else {
            $device = 'ios';
            $pttype['pt'] = '2';
        }
        try {
            $result = $client->push();
            $result->setPlatform($device);
            $result->addAlias($v['uid']);
            $result->setNotificationAlert($content);
            if ($pttype['pt'] == 1) {
                $result->androidNotification($content, array('title' => '爱打折', 'builder_id' => 1, 'extras' => array()));
            } else {
                $result->iosNotification($content, array('sound' => 'sound', 'badge' => '+1', 'content-available' => null, 'mutable-content' => null, 'category' => null, 'extras' => array()));
            }
            $result->setOptions(100000, 86400, null, false);
            $result->send();
        } catch (Exception $e) {
            echojson('操作成功', 1, $datas);
        }
    }

    if($time == '14' && $v['remind_time'] == '15'){
        if ($v['pt'] == 1) {
            $device = 'android';
            $pttype['pt'] = '1';
        } else {
            $device = 'ios';
            $pttype['pt'] = '2';
        }
        try {
            $result = $client->push();
            $result->setPlatform($device);
            $result->addAlias($v['uid']);
            $result->setNotificationAlert($content);
            if ($pttype['pt'] == 1) {
                $result->androidNotification($content, array('title' => '爱打折', 'builder_id' => 1, 'extras' => array()));
            } else {
                $result->iosNotification($content, array('sound' => 'sound', 'badge' => '+1', 'content-available' => null, 'mutable-content' => null, 'category' => null, 'extras' => array()));
            }
            $result->setOptions(100000, 86400, null, false);
            $result->send();
        } catch (Exception $e) {
            echojson('操作成功', 1, $datas);
        }
    }

    if($time == '19' && $v['remind_time'] == '20'){
        if ($v['pt'] == 1) {
            $device = 'android';
            $pttype['pt'] = '1';
        } else {
            $device = 'ios';
            $pttype['pt'] = '2';
        }
        try {
            $result = $client->push();
            $result->setPlatform($device);
            $result->addAlias($v['uid']);
            $result->setNotificationAlert($content);
            if ($pttype['pt'] == 1) {
                $result->androidNotification($content, array('title' => '爱打折', 'builder_id' => 1, 'extras' => array()));
            } else {
                $result->iosNotification($content, array('sound' => 'sound', 'badge' => '+1', 'content-available' => null, 'mutable-content' => null, 'category' => null, 'extras' => array()));
            }
            $result->setOptions(100000, 86400, null, false);
            $result->send();
        } catch (Exception $e) {
            echojson('操作成功', 1, $datas);
        }
    }

    if($time == '21' && $v['remind_time'] == '22'){
        if ($v['pt'] == 1) {
            $device = 'android';
            $pttype['pt'] = '1';
        } else {
            $device = 'ios';
            $pttype['pt'] = '2';
        }
        try {
            $result = $client->push();
            $result->setPlatform($device);
            $result->addAlias($v['uid']);
            $result->setNotificationAlert($content);
            if ($pttype['pt'] == 1) {
                $result->androidNotification($content, array('title' => '爱打折', 'builder_id' => 1, 'extras' => array()));
            } else {
                $result->iosNotification($content, array('sound' => 'sound', 'badge' => '+1', 'content-available' => null, 'mutable-content' => null, 'category' => null, 'extras' => array()));
            }
            $result->setOptions(100000, 86400, null, false);
            $result->send();
        } catch (Exception $e) {
            echojson('操作成功', 1, $datas);
        }
    }
}


function objtoarray1($obj) {
    if (is_object ( $obj )) {
        $obj = ( array ) $obj;
    }
    if ($obj)
        foreach ( $obj as $k => $o ) {
            if (is_object ( $o ) || is_array ( $o )) {
                $obj [$k] = objtoarray ( $o );
            }
        }
    return $obj;
}


?>